<?php

namespace Trawind\Helpers;


use Illuminate\Support\Arr;

class ArrHelper extends Arr
{

    public static function tree(
        $array,
        $pid = 0,
        string $parentKey = 'parent_id',
        string $childKey = 'child'
    ) {
        $tree = [];
        foreach ($array as $value) {
            if ($value[$parentKey] == $pid) {
                $value[$childKey] = self::tree($array, $value['id'],$parentKey,$childKey);
                $tree[] = $value;
            }
        }
        return $tree;
    }

}